package com.example.demo;

import com.ctrip.framework.apollo.spring.annotation.ApolloJsonValue;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * Created by BG314005 on 2018/7/20.
 */
@RestController
public class TestController {
    @Value("${redis.fds.fsd:999}")
    private String hello;
    @Value("${redis.hello.sfsa:999}")
    private String hello2;
    @Value("${test.string.hello}")
    private String hello3;

    @ApolloJsonValue("${test.json.hello:{\"a\":0, \"b\":\"0\"}}")
    private Test test;

    @Value("#{new java.text.SimpleDateFormat('${dateFormat}').parse('${dateProperty}')}")
    private Date date;

    @RequestMapping("/hello")
    public String testString() {
        return hello3 + hello + hello2;
    }

    @RequestMapping("/json")
    public Test testJson() throws IOException {
        return test;
    }

    @RequestMapping("/date")
    public String testDate() throws IOException {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
        String format = sdf.format(date);
        return format;
    }
//    @Autowired
//    private AppConfig appConfig;
    @Autowired
    private Test3 test3;

    @RequestMapping("/prefix")
    public String testPrefix() {
        return test3.getHello();
    }

    static class Test {
        private Integer a;
        private String b;
        private Test2 test2;

        public Integer getA() {
            return a;
        }

        public void setA(Integer a) {
            this.a = a;
        }

        public String getB() {
            return b;
        }

        public void setB(String b) {
            this.b = b;
        }

        public Test2 getTest2() {
            return test2;
        }

        public void setTest2(Test2 test2) {
            this.test2 = test2;
        }
    }

    static class Test2 {
        private Date c;

        public Date getC() {
            return c;
        }

        public void setC(Date c) {
            this.c = c;
        }
    }
}
